<?php
/**
 * Created by PhpStorm.
 * User: 徐州
 * Date: 2017/5/4
 * Time: 13:28
 */

namespace App\Models\VoteRecord;

use App\Models\User\User;
use \App\Models\VoteRecord\VoteRecord;
use Illuminate\Support\Facades\DB;

class VoteRecordRepository implements \App\Contracts\Repositories\VoteRecord\VoteRecordRepository
{

    /**
     * @param $conditions
     * @return mixed
     */
    public function where($conditions)
    {
        return VoteRecord::where($conditions)->get();
    }

    /**
     * 投票纪录
     * @param array|string $candidate_id
     * @return mixed
     */
    public function exportRecord($candidate_id)
    {
        if(!is_array($candidate_id)){
            $candidate_id = [$candidate_id];
        }
        $data = DB::table('vote_records')
            ->whereIn('vote_records.candidate_id', $candidate_id)
            ->leftJoin('vote_candidates', 'vote_candidates.id', 'vote_records.candidate_id')
            ->leftJoin('participants', 'vote_records.uid', '=', 'participants.uniqueid')
            ->select('participants.openid', 'participants.source', 'participants.username', 'participants.mobile', 'vote_candidates.title', 'vote_records.*')
            ->get();


        return $data;
    }


}
